<?php
/* @var $this QShiftController */
/* @var $qshiftData multidimensional array with qshift data*/
	
	//print_r($qshiftData);exit;

?>

<center>

<?php if ($qshiftData!=null): ?>

<h2> Q-Shifts For <?php echo $date; ?></h2> 
<br>


<?php
 //store current username
 $currentUsername = Yii::app()->user->id;

$rowCounter = 0;

foreach ($qshiftData as $rowKey => $row):

	if($rowCounter >= 4){
		echo '<span style="clear:both;display:block;"><br><hr><br></span>';
		$rowCounter=0;
	} 

?>	

<div id="<?php echo $row['idqshift']; ?>" class=<?php echo ($row['availability'])?  "qshift_box" : "qshift_box_not_avail"; ?> >
	
	<table>
		<tr>
			<th>
				<?php echo $row['name']; ?>
				<br>
				<?php echo $row['start_time'];?> | <?php echo $row['end_time'];?>
			</th>
		</tr>
		
		
		<?php 
		foreach ($row['users'] as $userKey => $user): 
		?>
		<tr>
			<td>
				<?php 
				
				echo CHtml::link(CHtml::encode($user['username']), 
									   Yii::app()->createUrl('/user/shortView', array('id' => $userKey)), 
									   array('target' => '_blank', 
											 'title' => $user['fullname'],
											 'style'=> ($user['username']==$currentUsername)? 'font-size:13px;color:#339900;font-weight:bold' : '',
											 )
								); 
				
				if($user['isQshiftSwap']) {
				
					echo CHtml::link(' *', 
									 Yii::app()->createUrl('/shiftChange/shortView', array('id' => $user['changeId'])), 
								     array('target' => '_blank', 'title' => 'View Swap','style'=>'color:blue;')
								); 	
									 
				} elseif($user['wasChanged']){
				
					echo CHtml::link(' **', 
									 Yii::app()->createUrl('/shiftChange/shortView', array('id' => $user['changeId'])), 
								     array('target' => '_blank', 'title' => 'View Shift Change','style'=>'color:red;')
								); 					
				}
				
				?>
			</td>
		</tr>
		<?php 
		endforeach; 
		?>
		
		<?php
		$callbacks = Callback::model()->findAll(array('condition'=>'date = "'.$date.'" and idqshift = '.$row['idqshift'],
													  'order'=>'time ASC'
													 )
												);
		
		//print_r($callbacks);
		
		if ($callbacks != null):
		?>
		
			<tr>
				<th>
					<?php echo "Callbacks"; ?>
				</th>
			</tr>

			<?php
			foreach ($callbacks as $callback):
			?>
			
			<tr>
				<td>
					<?php
						echo CHtml::link(CHtml::encode($callback->sr_number." -> ".$callback->time), 
											   Yii::app()->createUrl('/callback/view', array('id' => $callback->sr_number)), 
											   array('target' => '_blank', 
													 'title' => 'Click to view/edit Callback',
													 'style'=> ($callback->isAssigned)? 'font-size:10px;font-weight:normal;' : 'font-size:10px;color:#d23434;font-weight:bold',
													 )
										); 						
					?>
				</td>			
			</tr>
			
			
		<?php 
		
			endforeach; 
		endif;
		?>		
				
		
	</table>
</div>

<?php

$rowCounter++;


endforeach;
?>	

<?php else: ?>
<h2> No Active Q-Shifts Found For <?php echo $date; ?></h2> 
<br>

<?php endif; ?>
<center>
<span style="clear:both;display:block;"> &nbsp </span>